package cn.schoolwow.workflow.test.module.gateway.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.QuickWorkFlow;
import cn.schoolwow.workflow.domain.instance.WorkFlowInstanceStatus;
import cn.schoolwow.workflow.entity.WorkFlowInstance;
import cn.schoolwow.workflow.test.module.analyzeWorkReport.audit.single.common.CheckWorkFlowResult;
import cn.schoolwow.workflow.test.module.gateway.flow.StarLeaveConditionAuditFlow;

public class StartLeaveConditionAuditTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickWorkFlow quickWorkFlow = flowContext.checkInstanceData(QuickWorkFlow.class);
        {
            flowContext.startFlow(new StarLeaveConditionAuditFlow())
                    .next(new CheckWorkFlowResult())
                    .putCurrentCompositeFlowData("initiator", "张三")
                    .putInstanceData(WorkFlowInstanceStatus.Finished)
                    .putCurrentCompositeFlowData("leaveDay", 1)
                    .putCurrentCompositeFlowData("auditAssigner", "主管")
                    .execute();
            WorkFlowInstance workFlowInstance = flowContext.checkInstanceData(WorkFlowInstance.class);
            quickWorkFlow.deleteWorkFlowInstance(workFlowInstance.getId());
        }
        {
            flowContext.startFlow(new StarLeaveConditionAuditFlow())
                    .next(new CheckWorkFlowResult())
                    .putCurrentCompositeFlowData("initiator", "张三")
                    .putInstanceData(WorkFlowInstanceStatus.Finished)
                    .putCurrentCompositeFlowData("leaveDay", 2)
                    .putCurrentCompositeFlowData("auditAssigner", "经理")
                    .execute();
            WorkFlowInstance workFlowInstance = flowContext.checkInstanceData(WorkFlowInstance.class);
            quickWorkFlow.deleteWorkFlowInstance(workFlowInstance.getId());
        }
        {
            flowContext.startFlow(new StarLeaveConditionAuditFlow())
                    .next(new CheckWorkFlowResult())
                    .putCurrentCompositeFlowData("initiator", "张三")
                    .putInstanceData(WorkFlowInstanceStatus.Finished)
                    .putCurrentCompositeFlowData("leaveDay", 7)
                    .putCurrentCompositeFlowData("auditAssigner", "董事长")
                    .execute();
            WorkFlowInstance workFlowInstance = flowContext.checkInstanceData(WorkFlowInstance.class);
            quickWorkFlow.deleteWorkFlowInstance(workFlowInstance.getId());
        }
        {
            flowContext.startFlow(new StarLeaveConditionAuditFlow())
                    .next(new CheckWorkFlowResult())
                    .putCurrentCompositeFlowData("initiator", "王五")
                    .putInstanceData(WorkFlowInstanceStatus.Finished)
                    .putCurrentCompositeFlowData("leaveDay", 7)
                    .putCurrentCompositeFlowData("auditAssigner", "主管")
                    .execute();
            WorkFlowInstance workFlowInstance = flowContext.checkInstanceData(WorkFlowInstance.class);
            quickWorkFlow.deleteWorkFlowInstance(workFlowInstance.getId());
        }
    }

    @Override
    public String name() {
        return "请假条件分支测试用例";
    }
}
